<template>
<!-- 排行榜 -->
    <div class="ranlist">
        <div class="topheader">
            <div class="img">
                <img :src="lists.coverImgUrl" alt="">
            </div>
            <div class="title">
                {{lists.name}}
            </div>
            <div class="button" @click="$router.push('/searchs')">
                <span class="iconfont icon-arrow-left-bold"></span>
                排行榜
            </div>
        </div>
        <dl class="musicList">
            <dt @click="setAllId">
                <i class="fa fa-play-circle-o" aria-hidden="true" ></i> 播放全部 <span>(共{{i}}首)</span>
            </dt>
            <dd v-for="(item,index) in lists.tracks" :key="item.id" v-show="index<20" @click='setId(item.id)'>
                <h1>{{index+1}}</h1>
                <div class="info">
                    <h2>{{item.name}}</h2>
                    <h3>
                        <span v-for="(key) in item.ar" :key="key.id">{{key.name}}&nbsp;</span>
                    </h3>
                </div>
            </dd>
        </dl>
    </div>
</template>

<script>
    import {getPlaylistDetail} from "../../api/rank";
    export default {
      name: 'RankList',
        data() {
            return {
                lists:{},
                i:0
            }
        },
        created(){
            
            //根据歌单id查找10条音乐歌曲数据
            getPlaylistDetail({id:this.$route.query.id}).then(data=>{
                // 
                this.lists = data.playlist;
                this.i=this.lists.tracks.length;
                // 
            })
        },
        methods:{
            setId(id){
                // 子传父 调用父组件的方法
                this.$emit("get-player-id",id);
            },
            setAllId() {
                this.$emit('get-player-all-id',this.$route.query.id); //传递获取所有音乐的歌单id
                this.$emit("get-player-id",this.lists.tracks[0].id);//第一条音乐id
            }

        }
    }
</script>

<style lang="less" scoped>
h1,h2,h3{
  margin: 0;
}
    .topheader{
        position: relative;
        height: 270px;
        .img{
            background-color: aqua;
            width: 100%;
            height: 270px;
            position: relative;
            img{
                position: absolute;
                top:0px;
                left:0px;
                right: 0px;
                bottom: 0px;
                margin:auto;
                width: 100%;
            }
        }
        .title{
            font-size: 18px;
            position: absolute;
            left:18px;
            bottom:18px;
            color:#fff;
        }
        .button{
            font-size: 18px;
            position: absolute;
            left:12px;
            top:12px;
            color:#fff;
        }
    }
    .musicList{
        background-color: #fff;
        width: 100%;
        border-radius: 7px;
        position: relative;
        top:-7px;
        dt{
            height: 36px;
            line-height: 36px;
            font-size: 16px;
            color:#454747;
            border-bottom: 1px solid #E3E3E3;
            span{
                font-size: 14px;
                color:#797B7A;
            }
            i{
                width: 44px;
                text-align: center;
                display: inline-block;
            }
        }
        dd{
            border-bottom: 1px solid #E3E3E3;
            height: 53px;
            display: flex;
            h1{
                flex: 0 0 44px;
                line-height: 53px;
                text-align: left;
                font-size: 16px;
                color:#6D6E6E;
            }
            .info{
                flex:1;
                h2{
                    font-size: 16px;
                    color:#1B1C1C;
                    margin-top: 10px;
                    text-align: left;

                }
                h3{
                    font-size: 12px;
                    color:#929393;
                    text-align: left;

                }
            }
        }
    }
</style>